#include "Pin.h"

namespace cm_media
{
    Pin::Pin(PinDirection dir): m_direction(dir),
                                m_peer(NULL),
                                m_parent(NULL),
                                m_type(MediaTypeNull),
                                m_isConnected(false)
    {

    }

    Pin::~Pin()
    {

    }

    int Pin::connect( Pin* p_peer )
    {
        poco_assert(p_peer!=NULL);
        setPeer( p_peer );
        p_peer->receiveConnect( m_peer );
        m_isConnected = true;

        return CmMediaSucess;
    }

    int Pin::receiveConnect(Pin* p_peer )
    {
        poco_assert( p_peer!=NULL );
        setPeer(p_peer);
        m_isConnected = true;

        return CmMediaSucess;
    }

    int Pin::disconnect()
    {
        if( !m_isConnected ){
            return CmMediaFail;
        }

        poco_assert( m_peer!=NULL );
        m_peer->receiveDisconnect();
        m_peer = NULL;

        return CmMediaSucess;
    }

    int Pin::receiveDisconnect()
    {
        m_peer = NULL;
        m_isConnected = false;

        return CmMediaSucess;
    }

    bool Pin::isConnected()
    {
        return m_isConnected;
    }

    int Pin::setPeer(Pin* p_peer)
    {
        m_peer = p_peer;

        return CmMediaSucess;
    }

    Pin* Pin::getPeer()
    {
        return m_peer;
    }

    MediaType Pin::getMediaType()
    {
        return m_type;
    }

    PinDirection Pin::getDirection()
    {
        return m_direction;
    }

    Filter* Pin::getParent()
    {
        return m_parent;
    }

    

}